// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   DateUtility.java

package com.vandagroup.common.util;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtility
{

    public DateUtility()
    {
    }

    public static Date getCurrentDatetime()
    {
        return new Date(System.currentTimeMillis());
    }

    public static String getStringOfCurrentDatetime()
    {
        return datetimeToString(getCurrentDatetime());
    }

    public static String getStringOfCurrentDate()
    {
        return dateToString(getCurrentDatetime());
    }

    public static String getStringOfDayend(String day)
        throws Exception
    {
        if(day == null)
            return null;
        day = day.trim();
        if(day.length() == 0)
            return day;
        if(day.length() == 10)
            return day + " 24:00:00";
        if(day.length() == 19)
            return day.substring(0, 10) + " 24:00:00";
        else
            throw new Exception("���ڸ�ʽ����");
    }

    public static String datetimeToString(Date datetime)
    {
        if(datetime != null)
        {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return formatter.format(datetime);
        } else
        {
            return null;
        }
    }

    public static Date stringToDatetime(String datetime)
    {
        if(datetime != null)
        {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return formatter.parse(datetime, new ParsePosition(0));
        } else
        {
            return null;
        }
    }

    public static String dateToString(Date date)
    {
        if(date != null)
        {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            return formatter.format(date);
        } else
        {
            return null;
        }
    }

    public static Date stringToDate(String date)
    {
        if(date != null)
        {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            return formatter.parse(date, new ParsePosition(0));
        } else
        {
            return null;
        }
    }

    public static String timeToString(Date time)
    {
        if(time != null)
        {
            SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
            return formatter.format(time);
        } else
        {
            return null;
        }
    }

    public static Date stringToTime(String time)
    {
        if(time != null)
        {
            SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
            return formatter.parse(time, new ParsePosition(0));
        } else
        {
            return null;
        }
    }

    public static Date stringToDatetime(String date, String time)
    {
        if(date != null && time != null)
        {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return formatter.parse(date + " " + time, new ParsePosition(0));
        } else
        {
            return null;
        }
    }

    public static String getDate()
    {
        Calendar rightNow = Calendar.getInstance();
        int iY = rightNow.get(1);
        int iM = rightNow.get(2) + 1;
        int iD = rightNow.get(5);
        String strYear = String.valueOf(iY);
        String strMon = "";
        String strDay = "";
        if(iM < 10)
            strMon = "0" + iM;
        else
            strMon = String.valueOf(iM);
        if(iD < 10)
            strDay = "0" + iD;
        else
            strDay = String.valueOf(iD);
        return strYear + "-" + strMon + "-" + strDay;
    }

    public static String getTime()
    {
        Calendar rightNow = Calendar.getInstance();
        int iH = rightNow.get(11);
        int iM = rightNow.get(12);
        int iS = rightNow.get(13);
        String strH = null;
        String strM = null;
        String strS = null;
        if(iH < 10)
            strH = "0" + iH;
        else
            strH = String.valueOf(iH);
        if(iM < 10)
            strM = "0" + iM;
        else
            strM = String.valueOf(iM);
        if(iS < 10)
            strS = "0" + iS;
        else
            strS = String.valueOf(iS);
        return strH + ":" + strM + ":" + strS;
    }

    public static String getDateTime()
    {
        return getDate() + " " + getTime();
    }
}
